<template>
    <table>
        <tr>
            <td>门店名称</td>
            <td>
                <input type="text" v-model="states.name">
            </td>
        </tr>
        <tr>
            <td>门店地址</td>
            <td>
                <input type="text" v-model="states.address">
            </td>
        </tr>
        <tr>
            <td>备注</td>
            <td>
                <textarea cols="30" rows="3" v-model="states.remark"></textarea>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="添加" @click="add">
            </td>
        </tr>
    </table>
  </template>
  
  <script setup lang="ts">
  import{reactive, toRefs} from 'vue'
  import axios from 'axios'
  import {useRouter,useRoute} from 'vue-router'
  const route=useRoute()
  const router=useRouter()

  let data=reactive({
    states:{
        name:'',
        address:'',
        remark:'',
        state:"",
        isdel:''
    }
  })
  let{states} =toRefs(data)

  const add=()=>{
    if(states.value.name==""){
        alert("门店名称不能为空")
        return;
    }
    if(states.value.address==""){
        alert("门店地址不能为空")
        return;
    }
    if(states.value.remark==""){
        alert("备注不能为空")
        return;
    }
    let obj={
        "sname": states.value.name,
  "address": states.value.address,
  "remark": states.value.remark,
  "states": 1,
  "isDeleted": false
    }
    axios({
        url:'/api/Store/Addstore',
        method:'post',
        data:obj
    })
    .then(res=>{
        if(res.data.data==1){
            alert("注册门店成功")
            router.push('/storelist')
        }else{
            alert("注册门店失败")
        }
    })
    .catch(err=>{
        console.log(err)
    })
  }
  </script>
  
  <style scoped>
  
  </style>